﻿<script type="text/javascript">
    $(function () {
        getButton("dead_unstore");  //请求当前用户可以操作的按钮        
    });

    function ui_dead_unstore_init_list(toolbar) {
        $("#ui_dead_unstore_dg").datagrid({       //初始化datagrid
            url: "ashx/bg_dead.ashx?action=search",
            striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: false,
            idField: 'id',
            sortName: 'actFiretime',
            sortOrder: 'asc',
            pageList: [20, 40, 60, 80, 100],
            frozenColumns: [[
                { field: 'name', title: '姓名', width: 100 }
                
            ]],
            queryParams: {
                where: ' (starttime is null)  '
            },
            columns: [[                       
                       { field: 'gender', title: '性别', width: 40 },
                       { field: 'cardno', title: '身份证', width: 150 },
                       { field: 'actFiretime', title: '火化时间', sortable: true, width: 150 },
                       { field: 'estStoretime', title: '预存日期', sortable: true, width: 150 },
                       {
                           field: 'days', title: '相隔天数', width: 80, sortable: true,
                           formatter: function (value, row, index) {
                               return value && value.length > 20 ? '<span title="' + value + '">' + value + '</span>' : value;
                           }
                       },
                       {
                           field: 'estStoreplace', title: '预存骨灰堂', sortable: true, width: 160,
                           formatter: function (value, row, index) {
                               return value && value.length > 20 ? '<span title="' + value + '">' + value + '</span>' : value;
                           }
                       },
                       { field: 'areaName', title: '村（镇）', width: 100 },
                       { field: 'relativeName', title: '联系姓名', width: 100 },
                       { field: 'relativeTel', title: '联系电话', width: 100 },
                       { field: 'relationId', title: '与死者关系', width: 100 },
                       {
                           field: 'homeAddress', title: '地址', width: 250,
                           formatter: function (value, row, index) {
                               return value && value.length > 20 ? '<span title="' + value + '">' + value + '</span>' : value;
                           }
                       }
            ]],
            rowStyler: function (index, row) {
                if (row.days >= 30) {
                    return 'color:#CC6699;font-weight:bold;';
                }else if (row.days >= 15) {
                    return 'color:#FF0033;';
                } else if (row.days >= 7) {
                    return 'color:#333399;';
                }
                
            },
            toolbar: toolbar.length == 0 ? null : toolbar   //请求回来的当前用户可以操作的按钮            
        });
    }

    function ui_dead_unstore_searchdata() {
        var whereStr = "1=1";
        var days = $('#ui_dead_unstore_search').find('[name=ui_dead_unstore_search_days]').val();
        var areaid = $('#ui_dead_unstore_search_area').combotree('getValue');
        var starttime = $('#ui_dead_unstore_search').find('[name=ui_dead_unstore_search_dead_datestart]').val();
        var endtime = $('#ui_dead_unstore_search').find('[name=ui_dead_unstore_search_dead_dateend]').val();
        var bStore = $('#ui_dead_unstore_search').find('[name=ui_dead_unstore_search_store]').val();
        if (days != "") {
            whereStr += " and DATEDIFF(day, actFiretime, getdate())>=" + days;
        }
        
        if (areaid != "") {
            var aid = areaid.substr(9, 3);
            if (aid == "000") {
                whereStr += " and left(areacode,9)='" + areaid.substr(0, 9) + "'";
            } else {
                whereStr += " and areacode='" + areaid + "'";
            }
        }
        if (starttime != "") {
            whereStr += " and actFiretime >= '" + starttime + "'";
        }
        if (endtime != "") {
            whereStr += " and actFiretime <= '" + endtime + "'";
        }
        if (bStore == "Y") {
            whereStr += " and (graveid >= 0 and starttime  is not null )";
        } else{
            whereStr += " and (starttime is null)";
        }

        $("#ui_dead_unstore_dg").datagrid('load', {where:whereStr});
        $("#ui_dead_unstore_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_dead_unstore_layout').layout('collapse', 'east');    //隐藏
    }
    function ui_dead_unstore_cleardata() {
        $('#ui_dead_unstore_search input').val('');
        $('#ui_dead_unstore_search select').val('select');
        $('#ui_dead_unstore_search_dead_datestart').datebox('setValue', '');
        $('#ui_dead_unstore_search_dead_dateend').datebox('setValue', '');
        $("#ui_dead_unstore_dg").datagrid('load', { where: ' (starttime is null) ' });

        $("#ui_dead_unstore_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_dead_unstore_layout').layout('collapse', 'east');    //隐藏
    }
</script>
<div id="ui_dead_unstore_layout" class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false">
        <table id="ui_dead_unstore_dg" data-options="fit:true,border:false">
        </table>
    </div>
    <div data-options="region:'west',split:true,border:true,collapsed:true" title="多条件查询"
        style="width: 280px;">
        <div id="ui_dead_unstore_search">
            <table class="tableForm" style="width: 100%; height: 100%; background: #F5F5F5;">
                
                <tr>
                    <th>未存天数：
                    </th>
                    <td>
                        <input class="easyui-numberbox" name="ui_dead_unstore_search_days" id="ui_dead_unstore_search_days" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr> 
                <tr>
                    <th>是否入葬：
                    </th>
                    <td>
                        <select class="easyui-combobox" name="ui_dead_unstore_search_store" id="ui_dead_unstore_search_store" data-options="panelHeight:65,editable:false">                                                        
                            <option value="N">否</option>    
                            <option value="Y">是</option>                        
                        </select>
                    </td>
                </tr>                
                <tr>
                    <th>所属地区：
                    </th>
                    <td>                        
                        <input class="easyui-combotree" id="ui_dead_unstore_search_area" name="ui_dead_unstore_search_area"
                            data-options="url:'ashx/bg_area.ashx?action=getall', lines:true" />
                    </td>
                </tr>
                <tr>
                    <th>火化日期：
                    </th>
                    <td>
                        <input name="ui_dead_unstore_search_dead_datestart" id="ui_dead_unstore_search_dead_datestart" class="easyui-datebox"
                            editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <th>至：
                    </th>
                    <td>
                        <input name="ui_dead_unstore_search_dead_dateend" id="ui_dead_unstore_search_dead_dateend" class="easyui-datebox"
                            editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                            onclick="ui_dead_unstore_searchdata();">搜索</a>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                            onclick="ui_dead_unstore_cleardata();">清空条件</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
